<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>工程概况</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/layui/css/layui.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/admin.css"
      media="all"
    />
    <link
      rel="stylesheet"
      href="../../layuiadmin/style/style.css"
      media="all"
    />
  </head>
  <body>
    <div class="layui-fluid">
      <div class="" style="display: flex; position: relative">
        <div class="time_axis">
          <div class="time_box">
            <div class="time_box_list">
              <ul class="time_horizontal"></ul>
            </div>
          </div>
        </div>
        <div class="topButton">
          <div>
            <img
              src="../../layuiadmin/images/backPage.png"
              class="backPreviousPage"
              style="position: static"
            />
          </div>
          <button class="layui-btn layuiadmin-btn-useradmin downLoadWord">
            下载
          </button>
          <button class="layui-btn layuiadmin-btn-useradmin upLoadWord">
            上传
          </button>
          <button class="layui-btn layuiadmin-btn-useradmin deleteTechnical">
            删除
          </button>
        </div>
      </div>

      <iframe id="pdf" width="100%" height="800px"></iframe>
      <div class="seePdfBox"></div>
    </div>
    <script type="text/html" id="upLoadWordLayer">
      <div class="fileUploadDrag">
        <div class="layui-upload-drag" id="fileUpload">
          <i class="layui-icon"></i>
          <p>点击上传，或将文件拖拽到此处</p>
          <div class="layui-hide" id="uploadDemoVieww">
            <hr />
            <div class="fileUploadName"></div>
          </div>
        </div>
        <div class="fileUploadDelete"></div>
        <button class="layui-btn layui-btn-xs fileUploadButton">上传</button>
        <div class="PopupBotmBtn">
          <div>
            <button
              type="button"
              class="layui-btn projectTypeBtn cancelBtn"
              lay-submit=""
              lay-filter="draftUploadCancel"
              id="draftUploadCancel"
            >
              取消
            </button>
          </div>
          <div>
            <a class="sureBtn fileUploadBtn">确定</a>
          </div>
        </div>
      </div>
    </script>
    <script src="../../layuiadmin/modules/const_config.js"></script>
    <script src="../../layuiadmin/modules/jTools.js"></script>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script>
      layui
        .config({
          base: "../../layuiadmin/", //静态资源所在路径
        })
        .extend({
          index: "lib/index", //主入口模块
        })
        .use(["index", "upload"], function () {
          var table = layui.table,
            $ = layui.$,
            upload = layui.upload,
            uuid = layui.data("uuid").key,
            no = layui.data("no").key,
            type = layui.data("technicalType").key,
            fileid = "";
          $(
            '#LAY-system-side-menu dd[data-name="specialProtectionDraft"]',
            parent.document
          ).addClass("layui-this");
          permissionList();
          function permissionList() {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/SpecialProtection/createSpecialProtectionList",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ uuid, no, type }),
              success: function (data) {
                if (data.code == "200") {
                  if (data.state == "1") {
                    $(".upLoadWord").on("click", function () {
                      layer.open({
                        title:
                          '<i class="fa fa-plus"></i>&nbsp;专项保护方案草稿上传',
                        type: 1,
                        fix: false,
                        skin: "layui-layer-rim",
                        area: ["40%", "48%"],
                        content: $("#upLoadWordLayer").html(),
                        success: function (layero, index) {
                          var fileUploadUploadRender = upload.render({
                            elem: "#fileUpload",
                            elemList: $(".fileUploadDelete"), //列表元素对象
                            accept: "file",
                            auto: false,
                            url:
                              base_url +
                              "/SpecialProtection/uploadingSpecialProtection",
                            headers: {
                              Accept: "application/json; charset=utf-8",
                              Authorization: layui.sessionData("userToken").key,
                            },
                            bindAction: ".fileUploadButton",
                            before: function (obj) {
                              this.data = {
                                uuid: layui.data("uuid").key,
                              };
                              if ($(".fileUploadDelete").html() == "") {
                                return layer.msg(
                                  "请先选择文件",
                                  { time: 500 },
                                  function () {}
                                );
                              }
                              loadIndex = layer.load(2);
                            },
                            choose: function (obj) {
                              var that = this;
                              var files = (this.files = obj.pushFile()); //将每次选择的文件追加到文件队列 //读取本地文件
                              obj.preview(function (index, file, result) {
                                // $('.fileUploadButton').show()
                                let html = "";
                                html = $(
                                  [
                                    '<div id="upload-' +
                                      index +
                                      '" style="margin:5px 0">',
                                    "<span>" + file.name + "</span>",
                                    '<span style="margin-left:10px">',
                                    '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>',
                                    // ,'<button class="layui-btn layui-btn-xs layui-btn-danger fileUploadButton">上传</button>'
                                    "</span>",
                                    "</div>",
                                  ].join("")
                                );
                                //删除
                                html
                                  .find(".demo-delete")
                                  .on("click", function () {
                                    delete files[index]; //删除对应的文件
                                    html.remove();
                                    fileUploadUploadRender.config.elem.next()[0].value =
                                      "";
                                  });
                                that.elemList.append(html);
                              });
                            },
                            done: function (res, index, upload) {
                              var that = this;
                              if (res.code == 200) {
                                $(".fileUploadBtn").on("click", function () {
                                  layer.closeAll();
                                  permissionList();
                                });
                                var html = that.elemList.find(
                                  "div#upload-" + index
                                );
                                html.parent().children().html(""); //清空操作
                                delete this.files[index]; //删除文件队列已经上传成功的文件
                              }
                              layer.msg(
                                res.message,
                                { time: 10000 },
                                function () {}
                              );
                              layer.close(loadIndex);
                            },
                            error: function () {
                              layer.close(loadIndex);
                            },
                          });
                        },
                      });
                    });
                  } else if (data.state == "0") {
                    $(".upLoadWord").addClass("layui-btn-disabled");
                  }
                  var data = data.data.reverse();
                  var html = "";
                  for (var i = 0; i < data.length; i++) {
                    fileid = data[i].no;
                    var item = data[i].usersUpload;
                    if (i == data.length - 1) {
                      html += `
                      <li class="time_horizontal_part" data-id="${
                        data[i].pdfName
                      }" data-fileid="${fileid}" data-name="${
                        data[i].wordName
                      }">
                          <b class="active"></b>
                          ${data[i].createTime}<br/> 
                          ${
                            data[i].usersUpload == "1" ? "用户上传" : "自动生成"
                          } 
                        </li>`;
                      $("#pdf").attr(
                        "src",
                        "../../layuiadmin/web/viewer.html?file=" +
                          data[i].pdfName +
                          ""
                      );
                    } else {
                      html += `
                      <li class="time_horizontal_part" data-id="${
                        data[i].pdfName
                      }" data-fileid="${fileid}" data-name="${
                        data[i].wordName
                      }">
                          <b></b>
                          ${data[i].createTime}<br/>
                          ${
                            data[i].usersUpload == "1" ? "用户上传" : "自动生成"
                          } 
                      </li>`;
                    }
                  }
                  $(".time_horizontal").html(html);
                  $(".time_horizontal_part").on("click", function () {
                    var uuid = $(this).attr("data-id");
                    fileid = $(this).attr("data-fileid");
                    $(this).children("b").addClass("active");
                    $(this).siblings("li").children("b").removeClass("active");
                    $("#pdf").attr(
                      "src",
                      "../../layuiadmin/web/viewer.html?file=" + uuid
                    );
                  });
                  $(".downLoadWord").on("click", function () {
                    window.location.href = $(".active")
                      .parent()
                      .attr("data-name");
                  });
                  $(".time_horizontal").scrollLeft(
                    $(".time_horizontal")[0].scrollWidth
                  );
                } else {
                  layer.msg("专项保护方案列表为空", { icon: 6 });
                }

                // $("#pdf").attr("src","../../layuiadmin/web/viewer.html?file="+data[0].pdfName+"");
              },
            });
          }
          $(".deleteTechnical").on("click", function () {
            $.ajax({
              type: "post",
              async: true, //异步执行
              url: base_url + "/SpecialProtection/createdelect",
              headers: {
                Accept: "application/json; charset=utf-8",
                Authorization: layui.sessionData("userToken").key,
              },
              contentType: "application/json",
              data: JSON.stringify({ no: fileid }),
              success: function (data) {
                if ((data.type = "success")) {
                  layer.confirm("确认删除吗?", function (index) {
                    $(".active").parent().remove();
                    permissionList();
                    layer.msg(data.message, { icon: 6 });
                  });
                } else {
                  layer.msg(data.message, { icon: 5 });
                }
              },
            });
          });
          $(".backPreviousPage").on("click", function () {
            $(this).attr("lay-href", "./pages/technicalReview.html");
            $(
              '#LAY-system-side-menu li[data-name="technicalReview"]',
              parent.document
            ).removeClass("layui-nav-itemed");
            $(
              '#LAY-system-side-menu li[data-name="technicalReview"]',
              parent.document
            ).addClass("layui-this");
          });
        });
    </script>
  </body>
</html>
